﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;
using KeRui.Model;
using KeRui.BLL;

public partial class Manage_Cms_VoteItem : System.Web.UI.Page
{
   
    ManageErrMsg Err = new ManageErrMsg();
    protected string ActFlag = "addsave";
    protected string ActName = "添加";
    protected int SiteID = PageRequest.GetInt("SiteID", -1);
    protected void Page_Load(object sender, EventArgs e)
    {
        //管理员登录检查HYC
        ManageHelper.CheckAdminLogin();
        switch (ManageHelper.PageAct())
        {
            case "addsave":
                Add();
                break;
            default:
                break;
        }
    }

    /// <summary>
    /// 添加功能
    /// </summary>
    private void Add()
    {
        //权限检查HYC
        ManageHelper.CheckAdminPower("site_voteadd_" + SiteID);
        KeRui.Model.CmsVote CmsVoteModel = new KeRui.Model.CmsVote();
        KeRui.BLL.CmsVote BllCmsVote = new KeRui.BLL.CmsVote();
        KeRui.BLL.CmsVoteItem bllCmsVoteItem = new KeRui.BLL.CmsVoteItem();
        CmsVoteModel.SiteID = PageRequest.GetInt("siteid", -1);
        if (CmsVoteModel.SiteID == -1)
        {
            Err.AddErr("没有找到相应的站点！");
            Err.ChkErr();
        }
        //组装数据
        CmsVoteModel.VoteType = PageRequest.GetInt("radVoteType", -1);
        CmsVoteModel.VoteLimit = PageRequest.GetInt("radVoteLimit", -1);
        CmsVoteModel.Title = PageRequest.GetString("txtTitle");
        CmsVoteModel.Content = PageRequest.GetString("txtContent");
        CmsVoteModel.CreateIP = PageRequest.GetIP();
        int VoidID = BllCmsVote.Add(CmsVoteModel);
        int Count =int.Parse(PageRequest.GetString("txtMax"));
        KeRui.Model.CmsVoteItem CmsVoteItemModel = new KeRui.Model.CmsVoteItem();
        KeRui.BLL.CmsVoteItem BllCmsVoteItem = new KeRui.BLL.CmsVoteItem();
        //循环插入子表！
        for (int i = 0; i < Count;i++ )
        {
            CmsVoteItemModel.Title = PageRequest.GetString("txtContent"+i);
            CmsVoteItemModel.VoteNum = int.Parse(PageRequest.GetString("txtNum" + i));
            CmsVoteItemModel.VoteID = VoidID;
            CmsVoteItemModel.CreateTime = DateTime.Now;
            int Result = BllCmsVoteItem.Add(CmsVoteItemModel);
        }
        BllCmsVote.UpdateSum(VoidID);
        ManageHelper.AddLog("site_voteadd_" + SiteID, "添加了投票“" + CmsVoteModel.Title + "”。");//写日志HYC
        Response.Redirect("VoteList.aspx?sucmsg=添加成功。&siteID=" + CmsVoteModel.SiteID + "");
        
    }
}
